<template>
  <el-table :data="list" border fit stripe highlight-current-row style="width: 100%">
    <el-table-column loading="loading" align="center" label="ID" width="80px" sortable element-loading-text="请给我点时间！">
      <template slot-scope="scope">
        <span>{{ scope.row.id }}</span>
      </template>
    </el-table-column>

    <el-table-column width="240px" align="center" label="Number">
      <template slot-scope="scope">
        <span>{{ scope.row.number }}</span>
      </template>
    </el-table-column>

    <el-table-column min-width="120px" label="Name">
      <template slot-scope="{row}">
        <span>{{ row.name }}</span>
      </template>
    </el-table-column>

    <el-table-column width="120px" align="center" label="Role">
      <template slot-scope="scope">
        <span>{{ scope.row.role }}</span>
      </template>
    </el-table-column>

    <el-table-column width="120px" label="Permission">
      <template slot-scope="scope">
        <span>{{ scope.row.permission }}</span>
      </template>
    </el-table-column>

    <el-table-column align="center" label="Data" width="120px">
      <template slot-scope="scope">
        <span>{{ scope.row.data }}</span>
      </template>
    </el-table-column>

    <!--    <el-table-column class-name="status-col" label="Status" width="110">
      <template slot-scope="{row}">
        <el-tag :type="row.status | statusFilter">
          {{ row.status }}
        </el-tag>
      </template>
    </el-table-column>-->
  </el-table>
</template>

<script>
import { fetchList } from '@/api/article'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  props: {
    type: {
      type: String,
      default: 'admin'
    }
  },
  data() {
    return {
      list: null,
      listQuery: {
        page: 1,
        limit: 5,
        type: this.type,
        sort: '+id'
      },
      loading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.$emit('create') // for test
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.loading = false
      })
    }
  }
}
</script>

